/*
 * @copyright: ChengXuan
 * @Author: ding
 * @Date: 2022-07-27 17:30:36
 * @LastEditors: ding
 * @LastEditTime: 2022-07-27 17:57:42
 * @Description: file content
 */

import { Application, Context } from "egg";
import { archive } from "../../lib/core/logs-archive";

module.exports = (app: Application) => {
  return {
    schedule: {
      cron: "4 33 0 * * ?",
      type: "worker",
    },
    async task(ctx: Context) {
      const d = new Date();
      d.setDate(d.getDate() - 1);
      const year = d.getFullYear();
      let month = d.getMonth() + 1;
      let date = d.getDate();
      // @ts-ignore
      month = month.toString().padStart(2, "0");
      // @ts-ignore
      date = date.toString().padStart(2, "0");

      const dateStr = `${year}-${month}-${date}`;
      archive(dateStr, ctx.app.config);
      app.logger.info("[dinegg] 定时归档日志文件完成！");
    },
  };
};
